/**
 * @author:cloud.lg
 * @date:2021.7.26
 * @description: 定义本地缓存模块 vuex
 */
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import mutations from './mutation'
import actions from './action'
import getters from './getter'
import { apiUrl } from '@/utils/env'
Vue.use(Vuex)

let state = {
    token: '',
    isCollapse: false,
    editableTabs: [],
    reloadFlag: false,
    editableTabsValue: '',
    userInfo: {}, // 用户信息
    isSystem: '', // 1--系统管理员 0--非系统管理员
    menuData: []
};

const modulesFiles = require.context('./modules', true, /\.js$/)

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  // set './app.js' => 'app'
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  const value = modulesFiles(modulePath)
  modules[moduleName] = value.default
  return modules
}, {})

const vuexPersisted = new createPersistedState({
    //TODO
    /* key:customLocalName,
     storage: window.localStorage,
     }),
     filter: mutation => (
     )*/
});

export default new Vuex.Store({
    actions,
    mutations,
    state,
    getters,
    modules,
    plugins: [vuexPersisted]
});